#include "StdAfx.h"
#include "DxShaderManager.h"
#include "DxVertexShader.h"
#include "DxPixelShader.h"
#include "DxRenderer.h"

DxShaderManager* DxShaderManager::sm_pShaderManager = 0;

DxShaderManager::DxShaderManager(void)
{
	DxRenderer* pRenderer = DxRenderer::GetInstance();
	m_pDefaultVS = new DxVertexShader();
	m_pDefaultVS->LoadFromFile("../Graphics/Shaders/DefaultVS.so", pRenderer);

	m_pDefaultPS = new DxPixelShader();
	m_pDefaultPS->LoadFromFile("../Graphics/Shaders/DefaultPS.so", pRenderer);
}

DxShaderManager::~DxShaderManager(void)
{
	if( m_pDefaultVS )
		delete m_pDefaultVS;

	if( m_pDefaultPS )
		delete m_pDefaultPS;
}

DxVertexShader* DxShaderManager::GetVertexShader(char* szName)
{
	u32 uHash = StringHash(szName);
	return GetVertexShader(uHash);
}

DxVertexShader* DxShaderManager::GetVertexShader(u32 uHash)
{
	DxVertexShader** shader = m_mVertexShaders[uHash];

	if( shader) 
		return *shader;

	return 0;
}

DxPixelShader* DxShaderManager::GetPixelShader(char* szName)
{
	u32 uHash = StringHash(szName);
	return GetPixelShader(uHash);
}

DxPixelShader* DxShaderManager::GetPixelShader(u32 uHash)
{
	DxPixelShader** shader = m_mPixelShaders[uHash];

	if( shader) 
		return *shader;

	return 0;

}

DxShaderManager* DxShaderManager::GetInstance()
{
	if( !sm_pShaderManager )
		sm_pShaderManager = new DxShaderManager();

	return sm_pShaderManager;
}